<?php
header ( 'Content-Type:text/html; charset=UTF-8' );
$pdo = new PDO ( 'mysql:dbname=atm;charset=utf8', 'root' );
@$account = $_REQUEST ['account'];
@$password = $_REQUEST ['password'];
$s = $pdo->prepare ( 'select * from username' );
$s->execute ();
$data = $s->fetchAll ( PDO::FETCH_NAMED );
if (! empty ( $account ) && ! empty ( $password )) {
	foreach ( $data as $value ) {
		if ($account == $value ['name']) {
			break;
		}
	}
	if ($account != $value ['name']) {
		echo json_encode ( array (
				'zt' => false,
				'fhwb' => '用户不存在' 
		) );
	} elseif ($password == $value ['password']) {
		session_start ();
		$_SESSION ['user'] = $account;
		echo json_encode ( array (
				'zt' => true,
				'fhwb' => '登录成功' 
		) );
	} else {
		echo json_encode ( array (
				'zt' => false,
				'fhwb' => '密码错误' 
		) );
	}
} else {
	echo json_encode ( array (
			'zt' => false,
			'fhwb' => '用户名和密码不能为空' 
	) );
}
?>

